﻿@using KRM.Core
@model List<tblAddress>

@{
    tblAddress contact;
    tblAddress billing = null;

    if (Model.Count == 1)
    {
        contact = Model.FirstOrDefault() ?? new tblAddress();
    }
    else
    {
        contact = Model.FirstOrDefault(a => a.BillingAddress == false);
        billing = Model.FirstOrDefault(a => a.BillingAddress == true);
    }

    var customer = new KRMEntities().tblCustomers.Find(contact.CustomerID);
    var vips = new KRMEntities().tblVIPStatuses.ToList();
    vips.Insert(0, new tblVIPStatus() { Name = "Choose a status" });
    vips.Insert(1, new tblVIPStatus() { Id = 0, Name = "None" });
    ViewBag.VipStatusId = new SelectList(vips, "Id", "Name", customer.VIPStatusId);
}

@Html.Partial("Partial/_MessageResult")
<form action="/orderview/SaveCustomerAddress" method="POST" id="fr-customerorderaddress">
    <input type="hidden" name="CustomerID" id="CustomerID" value="@contact.CustomerID"/>
    <div class="row-fluid">
        <fieldset class="span6">
            <legend>Customer Delivery Address</legend>
            <div class="row-fluid">
                <div class="span3">Name</div>
                <div class="span3">
                    <select class="input-block-level" name="title" id="title">
                        <option value="Mr" @(contact.Title == "Mr" ? "selected=selected" : "")>Mr</option>
                        <option value="Mrs" @(contact.Title == "Mrs" ? "selected=selected" : "")>Mrs</option>
                        <option value="Ms" @(contact.Title == "Ms" ? "selected=selected" : "")>Ms</option>
                        <option value="Miss" @(contact.Title == "Miss" ? "selected=selected" : "")>Miss</option>
                        <option value="Dr" @(contact.Title == "Dr" ? "selected=selected" : "")>Dr</option>
                        <option value="Rev" @(contact.Title == "Rev" ? "selected=selected" : "")>Rev</option>
                    </select>
                </div>
                <div class="span3">
                    <input type="text" class="input-block-level" name="Forename" id="Forename" value="@contact.Forename" required="required" />
                </div>
                <div class="span3">
                    <input type="text" class="input-block-level" name="Surname" id="shipSurname" value="@contact.Surname" required="required" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Address Line1:</div>
                <div class="span6">
                    <input type="text" class="input-block-level" name="AddressLine1" id="AddressLine1" value="@contact.AddressLine1" required="required" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Address Line2:</div>
                <div class="span6">
                    <textarea class="input-block-level" name="AddressLine2" id="AddressLine2" required="required">@contact.AddressLine2</textarea>
                </div>
                <div class="span3 text-center">
                    @if (customer.VIPStatusId > 0)
                    {
                        <h1 style="color: red">VIP</h1>
                    }
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Town</div>
                <div class="span6">
                    <input type="text" class="input-block-level" name="Town" id="Town" value="@contact.Town" required="required" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">County</div>
                <div class="span6">
                    <input type="text" class="input-block-level" name="County" id="County" value="@contact.County" required="required" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Postcode</div>
                <div class="span4">
                    <input type="text" class="input-block-level" name="postcode" id="PostcodeShipping" value="@contact.Postcode" required="required" />
                </div>
                <div class="span2">
                    <input type="button" value="Lookup" class="btn btn-primary input-block-level" onclick="lookuppostcode(false)" style="width: 100%" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Phone</div>
                <div class="span6">
                    <input type="text" class="input-block-level" name="phone" id ="Phone" value="@contact.Telephone1@Html.Raw("\n")@contact.Telephone2" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Mobile</div>
                <div class="span6">
                    <input type="text" class="input-block-level" name="Mobile" id="Mobile" value="@contact.Mobile" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3"></div>
                <div class="span6">
                    <label>
                        <input type="checkbox" class="cbcheck cbSeparate" onchange="SeparateBilling()" @(billing != null ? "checked=checked" : "") name="cbSeparate" />
                        Separate Billing Address?                 
                    </label>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Email</div>
                <div class="span6">
                    <input type="text" class="input-block-level" name="emailaddress" id="EmailAddress" value="@customer.EmailAddress" />
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3"></div>
                <div class="span7">
                    <label>
                        <input type="checkbox" class="cbcheck" @(customer.ReceiveNewsletter ? "checked=checked" : "") name="ReceiveNewsletter" />
                        Receive Newsletter?                 
                    </label>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span3">Vip Status</div>
                <div class="span6">
                    @Html.DropDownList("VipStatusId", null, new {@class="input-block-level", required = "required"})
                </div>
            </div>
        </fieldset>
        @if (billing != null)
        {
            <fieldset class="span6 seperatebilling" style="display: block; height: 519px;">
                <legend>Seperate Billing Address</legend>
                <div class="row-fluid">
                    <div class="span3">Name</div>
                    <div class="span3">
                        <select class="input-block-level" name="billtitle" id="billtitle">
                            <option value="Mr" @(billing.Title == "Mr" ? "selected=selected" : "")>Mr</option>
                            <option value="Mrs" @(billing.Title == "Mrs" ? "selected=selected" : "")>Mrs</option>
                            <option value="Ms" @(billing.Title == "Ms" ? "selected=selected" : "")>Ms</option>
                            <option value="Miss" @(billing.Title == "Miss" ? "selected=selected" : "")>Miss</option>
                            <option value="Dr" @(billing.Title == "Dr" ? "selected=selected" : "")>Dr</option>
                            <option value="Rev" @(billing.Title == "Rev" ? "selected=selected" : "")>Rev</option>
                        </select>
                    </div>
                    <div class="span3">
                        <input type="text" class="input-block-level" name="billForename" id ="billForename" value="@billing.Forename" />
                    </div>
                    <div class="span3">
                        <input type="text" class="input-block-level" name="billSurname" id ="billSurname" value="@billing.Surname" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Address Line1</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" name="billAddressLine1" id="billAddressLine1" value="@billing.AddressLine1" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Address Line2</div>
                    <div class="span6">
                        <textarea class="input-block-level" name="billAddressLine2" id="billAddressLine2">@billing.AddressLine2</textarea>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Town</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" name="billTown" id="billTown" value="@billing.Town" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">County</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" name="billCounty" id="billCounty" value="@billing.County" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Postcode</div>
                    <div class="span4">
                        <input type="text" class="input-block-level" name="billpostcode" id="billPostcode" value="@billing.Postcode" />
                    </div>
                    <div class="span2">
                        <input type="button" value="Lookup" class="btn btn-primary input-block-level" onclick="lookuppostcode(true)" style="width: 100%" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Phone</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" value="@billing.Telephone1@Html.Raw("\n")@billing.Telephone2" name="billPhone" id="billPhone" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Mobile</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" name="billMobile" id="billMobile" value="@billing.Mobile" />
                    </div>
                </div>

            </fieldset>
        }
        else
        {
            <fieldset class="span6 seperatebilling" style="display: none; height: 519px;">
                <legend>Seperate Billing Address</legend>
                <div class="row-fluid">
                    <div class="span3">Name</div>
                    <div class="span3">
                        <select class="input-block-level" name="billtitle" id="billtitle">
                            <option value="Mr" @(contact.Title == "Mr" ? "selected=selected" : "")>Mr</option>
                            <option value="Mrs" @(contact.Title == "Mrs" ? "selected=selected" : "")>Mrs</option>
                            <option value="Ms" @(contact.Title == "Ms" ? "selected=selected" : "")>Ms</option>
                            <option value="Miss" @(contact.Title == "Miss" ? "selected=selected" : "")>Miss</option>
                            <option value="Dr" @(contact.Title == "Dr" ? "selected=selected" : "")>Dr</option>
                            <option value="Rev" @(contact.Title == "Rev" ? "selected=selected" : "")>Rev</option>
                        </select>
                    </div>
                    <div class="span3">
                        <input type="text" class="input-block-level" name="billForename" id="billForename" value="@contact.Forename" />
                    </div>
                    <div class="span3">
                        <input type="text" class="input-block-level" name="billSurname" id ="billSurname" value="@contact.Surname" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Address Line1</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" name="billAddressLine1" id="billAddressLine1" value="@contact.AddressLine1" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Address Line2</div>
                    <div class="span6">
                        <textarea class="input-block-level" name="billAddressLine2" id="billAddressLine2">@contact.AddressLine2</textarea>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Town</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" name="billTown" id="billTown" value="@contact.Town" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">County</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" name="billCounty" id="billCounty" value="@contact.County" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Postcode</div>
                    <div class="span4">
                        <input type="text" class="input-block-level" name="billpostcode" id="billPostcode" value="@contact.Postcode" />
                    </div>
                    <div class="span2">
                        <input type="button" value="Lookup" class="btn btn-primary input-block-level" onclick="lookuppostcode(true)" style="width: 100%" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Phone</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" value="@contact.Telephone1@Html.Raw("\n")@contact.Telephone2" name="billPhone" id="billPhone" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Mobile</div>
                    <div class="span6">
                        <input type="text" class="input-block-level" name="billMobile" id="billMobile" value="@contact.Mobile" />
                    </div>
                </div>

            </fieldset>
        }
    </div>
    <div class="row-fluid">
        <fieldset class="span6" style="height: 129px;">
            <legend>Payment Details</legend>
            <div class="row-fluid">
                <div class="span3">Payment method</div>
                <div class="span4">
                    <select class="input-block-level" name="cbpayment" id="cbpayment" onchange="javascript:if(this.value == 'Cheque Payment')alert('This order will be saved in the pending phone orders as it is a cheque payment');">
                        <option value="Credit card">Credit card</option>
                        <option value="Cheque Payment">Cheque Payment</option>
                    </select>
                </div>
            </div>
            @*<div class="row-fluid">
            <div class="span3">Trade Orderref</div>
            <div class="span3">
                <input type="text" class="input-block-level" />
            </div>
            <div class="span2">Po Number</div>
            <div class="span4">
                <input type="text" class="input-block-level" />
            </div>
        </div>*@
        </fieldset>
        <fieldset class="span6">
            <legend>Delivery Instructions</legend>
            <p>Enter any special delivery instructions below</p>
            <div class="row-fluid">
                <div class="span12">
                    <textarea class="input-block-level" name="SpecialIns" id="SpecialIns">No Special Instructions supplieds</textarea>
                </div>
            </div>
            @*<div class="row-fluid">
            <div class="span3">Order Date</div>
            <div class="span9">
                <div class="input-append datetimepicker">
                    <input data-format="dd/MM/yyyy HH:mm:ss PP" type="text" name="PreferredCollectionDate" value="@DateTime.Now" />
                    <span class="add-on">
                        <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                    </span>
                </div>
            </div>
        </div>*@
        </fieldset>
    </div>
    <div class="row-fluid">
        <div class="span4">
            <p style="padding: 5px 0 0 10px; margin: 0">Using an Existing customer: @contact.Title @contact.Forename @contact.Surname</p>
        </div>
        <div class="span3">
            <input type="submit" value="Save Customer Details" class="btn btn-primary" />
        </div>
    </div>
</form>